package com.ruoyi.doctor.service.impl;


import com.ruoyi.doctor.domain.DoctorPatient;
import com.ruoyi.doctor.domain.DoctorPeople;
import com.ruoyi.doctor.mapper.DoctorPatientMapper;
import com.ruoyi.doctor.service.DoctorPatientService;
import com.ruoyi.system.domain.SysRegister;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class DoctorPatientServiceImpl implements DoctorPatientService {

    @Autowired
    DoctorPatientMapper mapper;

    @Override
    public DoctorPatient queryBy(DoctorPatient patient) {
        return null;
    }

    @Override
    public DoctorPatient queryBySfz(String patientCard) {
        return mapper.queryBySfz(patientCard);
    }

    @Override
    public List<DoctorPeople> queryByDept(String deptName) {
        return mapper.queryByDept(deptName);
    }

    @Override
    public SysRegister queryFee(Long regisId,int patientId) {
        mapper.updateRegis(patientId, regisId);
        return mapper.queryFee(regisId);
    }

    //患者选择科室添加科室
    @Override
    public int addDept(int patientId,Long deptId) {
        mapper.updateDept(patientId, Math.toIntExact(deptId));
        return mapper.addDept(patientId, deptId);
    }

    @Override
    public int updatePeople(int deptId, int beforecode) {
        int i = beforecode+1;
        return mapper.updatePeople(deptId,i);
    }

    //添加患者
    @Override
    public int addPatient(DoctorPatient patient) {
        //设置挂号的编号和流水号
        String GH = "GH"+ (new Random().nextInt(89999999) + 10000000);
        int tracking = (new Random().nextInt(89) + 10);
        patient.setPatientNum(tracking);
        patient.setRegisTracking(GH);
        patient.setRegisTime("白天");
        mapper.addPatient(patient);
        System.out.println(patient.getPatientId());
        return patient.getPatientId();
    }


    //修改挂号类型


   /* @Override
    public SysPatient queryBySfz(SysPatient patient) {
        return mapper.queryBySfz(patient);
    }*/
}
